unit udmActionList;

interface

uses
  System.SysUtils, System.Classes, System.Actions, FMX.ActnList;

type
  TdmActionList = class(TDataModule)
    alMainActionList: TActionList;
    acProject_New: TAction;
    acFile_Open: TAction;
    acFile_Save: TAction;
    acFile_SaveAs: TAction;
    acFile_Export: TAction;
    acFile_Project: TAction;
    acProject_Find: TAction;
    acFile_Print: TAction;
    acFile_PrintPreview: TAction;
    acFile_Close: TAction;
    acProject_Move: TAction;
    acProject_Delete: TAction;
    acProject_Sync: TAction;
    acProject_Sort: TAction;
    acEdit_Copy: TAction;
    acEdit_Paste: TAction;
    acEdit_Cut: TAction;
    acProjectPage_Close: TAction;
    acProjectPage_CloseAll: TAction;
    acProjectCatalogs_New: TAction;
    acProjectCatalogs_Delete: TAction;
    acProjectCatalogs_Rename: TAction;
    acProjectPage_CloseByProjectAll: TAction;
    acProjectPage_CloseByProjectDicAll: TAction;
    procedure acFile_CloseExecute(Sender: TObject);
    procedure acProjectPage_CloseUpdate(Sender: TObject);
    procedure acProjectPage_CloseExecute(Sender: TObject);
    procedure acFile_CloseUpdate(Sender: TObject);
    procedure acProjectPage_CloseAllUpdate(Sender: TObject);
    procedure acProjectPage_CloseAllExecute(Sender: TObject);
    procedure acProjectCatalogs_NewUpdate(Sender: TObject);
    procedure acProjectCatalogs_DeleteUpdate(Sender: TObject);
    procedure acProjectCatalogs_RenameUpdate(Sender: TObject);
    procedure acProjectCatalogs_NewExecute(Sender: TObject);
    procedure acProjectCatalogs_DeleteExecute(Sender: TObject);
    procedure acProjectCatalogs_RenameExecute(Sender: TObject);
    procedure acProjectPage_CloseByProjectAllUpdate(Sender: TObject);
    procedure acProjectPage_CloseByProjectAllExecute(Sender: TObject);
    procedure acProjectPage_CloseByProjectDicAllUpdate(Sender: TObject);
    procedure acProjectPage_CloseByProjectDicAllExecute(Sender: TObject);
    procedure acProject_DeleteUpdate(Sender: TObject);
    procedure acProject_NewUpdate(Sender: TObject);
    procedure acProject_NewExecute(Sender: TObject);
    procedure acProject_DeleteExecute(Sender: TObject);
  private
  public
  end;

var
  dmActionList: TdmActionList;

implementation

{%CLASSGROUP 'FMX.Types.TFmxObject'}

{$R *.dfm}


uses FMX.Forms, FMX.Messages, FMX.Dialogs, ufProjectManager, uProjectDic;


procedure TdmActionList.acFile_CloseExecute(Sender: TObject);
begin
  Application.Terminate
end;

procedure TdmActionList.acFile_CloseUpdate(Sender: TObject);
begin
  acFile_Close.Enabled:= True;
end;

procedure TdmActionList.acProjectCatalogs_DeleteExecute(Sender: TObject);
begin
  fProjectManager.dlgDeleteCatalog();
end;

procedure TdmActionList.acProjectCatalogs_DeleteUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:= (fProjectManager <> nil) and
    (fProjectManager.ProjectLists.ActiveDicView <> nil) and
    (fProjectManager.ProjectLists.ActiveDicView.ProjectDic.CanDelete);
end;

procedure TdmActionList.acProjectCatalogs_NewExecute(Sender: TObject);
begin
  fProjectManager.dlgNewCatalog();
end;

procedure TdmActionList.acProjectCatalogs_NewUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:=
    (fProjectManager <> nil) and (fProjectManager.ProjectLists.ActiveDicView <> nil);
end;

procedure TdmActionList.acProjectCatalogs_RenameExecute(Sender: TObject);
begin
  fProjectManager.dlgRenameCatalog();
end;

procedure TdmActionList.acProjectCatalogs_RenameUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:= (fProjectManager <> nil) and
    (fProjectManager.ProjectLists.ActiveDicView <> nil) and
    (fProjectManager.ProjectLists.ActiveDicView.ProjectDic.CanRename);
end;

procedure TdmActionList.acProjectPage_CloseAllExecute(Sender: TObject);
begin
  fProjectManager.ProjectLists.PageButtons.CloseAll();
end;

procedure TdmActionList.acProjectPage_CloseAllUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:= (fProjectManager <> nil) and (fProjectManager.ProjectLists.PageButtons.Count > 0);
end;

procedure TdmActionList.acProjectPage_CloseByProjectAllExecute(Sender: TObject);
begin
  fProjectManager.ProjectLists.PageButtons.CloseProjectToolBottons(
    TPageButton(fProjectManager.ProjectLists.PageButtons.ActiveButton).Project
  );
end;

procedure TdmActionList.acProjectPage_CloseByProjectAllUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:= (fProjectManager <> nil) and (fProjectManager.ProjectLists.PageButtons.ActiveButton <> nil)
end;

procedure TdmActionList.acProjectPage_CloseByProjectDicAllExecute(Sender: TObject);
begin
  fProjectManager.ProjectLists.PageButtons.CloseProjectDicToolBottons(
    TPageButton(fProjectManager.ProjectLists.PageButtons.ActiveButton).Project.ProjectDic
  );
end;

procedure TdmActionList.acProjectPage_CloseByProjectDicAllUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:= (fProjectManager <> nil) and (fProjectManager.ProjectLists.PageButtons.ActiveButton <> nil)
end;

procedure TdmActionList.acProjectPage_CloseExecute(Sender: TObject);
begin
  fProjectManager.ProjectLists.PageButtons.ActiveButton.Close(True);
end;

procedure TdmActionList.acProjectPage_CloseUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:= (fProjectManager <> nil) and (fProjectManager.ProjectLists.PageButtons.ActiveButton <> nil);
end;

procedure TdmActionList.acProject_DeleteExecute(Sender: TObject);
begin
  fProjectManager.dlgDeleteProject();
end;

procedure TdmActionList.acProject_DeleteUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:=
    ((fProjectManager <> nil) and (fProjectManager.ProjectLists.ActiveDicView <> nil)) and
    (fProjectManager.ProjectLists.ActiveDicView.ActiveProject <> nil);
end;

procedure TdmActionList.acProject_NewExecute(Sender: TObject);
begin
  fProjectManager.dlgNewProject();
end;

procedure TdmActionList.acProject_NewUpdate(Sender: TObject);
begin
  TAction(Sender).Enabled:=
    (fProjectManager <> nil) and (fProjectManager.ProjectLists.ActiveDicView <> nil) and not
    (TProjectDicEditRestrictions.perArchives in fProjectManager.ProjectLists.ActiveDicView.ProjectDic.EditRestrictions);
end;

end.
